-
Notifications
You must be signed in to change notification settings - Fork 205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
make exercise by interface contract ID safe #14134
Conversation
Maybe for some useful context: The way I’m imaging most of our usage will look like is that we’ll call an interface choice on an interface contract id. I don’t actually care much about being able to call an interface choice on a template contract id. So I think a design where we have:
is worth considering imho. |
I have a prototype interface that appears to do the right things, accepting and rejecting the proper expressions, as explained in the sample function therein. Specifically, this makes quite a different representation of interface contract IDs from that in #11280 (and will remove |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall I like it. The "hack" to avoid the variance issues in ToInterface doesn’t feel particularly nice but I amit I don’t have a better idea. What happens if we drop that? Does that make all casts typecheck or only if you specify never
explicitly as the type?
I’d also be interested to see examples of:
1 Interplay with retroactive implementations. In your example you seem to extend TI
from T
. It’s not clear to me how this is extended to reotractive implementations where you don’t know the set of implemented interfaces upfront.
2. Interplay with interface hierarchies
I'm not really sure. The problem with predicting this is that, as the comment mentions, a surprising number of type expressions are = to All of the examples in the file work out the same if I drop the conditional. But I can then pass
This will never happen, even with retroactives. We codegen on the whole environment.
None of the codegens model these at all, only template/interface relationships. |
This is not really how daml2js works atm. Yes it has a complete environment in theory but the way it process things atm it looks at one package at a time and its dependencies not the whole package. I also don’t think it’s as simple as just looking at the whole environment: Consider this example:
Daml2js generates each LF package as a separate JS package. In this example you would thus have two JS package. |
We can deal with this, since we can pass extra arguments about the environment. #14082
I agree this is a problem. The module dependencies end up potentially circular and breaking here. I'd rather not add |
That sounds sensible to me. I think it’s worth thinking about whether we can use a similar design in the JVM codegens but that’s a separate conversation. |
…ercise-interface-contract-id-safe
@chunlokling-da and I reworked the prototype to properly support retroactive implementations; see the new version here. Key changes:
What do you think @cocreature ? |
…ercise-interface-contract-id-safe
CHANGELOG_BEGIN - [TypeScript codegen] To exercise an interface choice on a template-typed contract ID, you must now explicitly convert the contract ID to an interface-typed ID. For example, where ``cid: ContractId<TemplateName>``, you can use ``TemplateName.toInterface(InterfaceName, cid)`` to produce a ``ContractId<InterfaceName>``. Interface contract IDs are also now typed as shown above; for example, the former type ``ContractId<InterfaceNameInterface<TemplateName>>`` would now simply be ``ContractId<InterfaceName>``. CHANGELOG_END
Fixes #14132.